#include "widget.h"
#include "ui_widget.h"
#include "solarlunarconverter.h"
#include <QDate>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    connect(ui->pushButton, &QPushButton::clicked, this, &Widget::slotClicked);

    QDate date = QDate::currentDate();

    ui->lineEdit_in_year->setText(QString::number(date.year()));
    ui->lineEdit_in_month->setText(QString::number(date.month()));
    ui->lineEdit_in_day->setText(QString::number(date.day()));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::slotClicked()
{
    int year = ui->lineEdit_in_year->text().toInt();
    int month = ui->lineEdit_in_month->text().toInt();
    int day = ui->lineEdit_in_day->text().toInt();

    SolarLunarConverter converter;
    SolarLunarInfo *info = converter.solar2lunar(year, month, day);

    ui->lineEdit_out_1->setText(QString::number(info->solarYear));
    ui->lineEdit_out_2->setText(QString::number(info->solarMonth));
    ui->lineEdit_out_3->setText(QString::number(info->solarDay));
    ui->lineEdit_out_4->setText(info->animal);
    ui->lineEdit_out_5->setText(info->lunarMonthChineseName);
    ui->lineEdit_out_6->setText(QString::number(info->lunarYear));
    ui->lineEdit_out_7->setText(QString::number(info->lunarMonth));
    ui->lineEdit_out_8->setText(QString::number(info->lunarDay));
    ui->lineEdit_out_9->setText(QString::number(info->isLeap));
    ui->lineEdit_out_10->setText(info->lunarDayChineseName);
    ui->lineEdit_out_11->setText(info->ganzhiYear);
    ui->lineEdit_out_12->setText(info->ganzhiMonth);
    ui->lineEdit_out_13->setText(info->ganzhiDay);
    ui->lineEdit_out_14->setText(info->term);
    ui->lineEdit_out_15->setText(QString::number(info->isTerm));
}
